<template>
	<view>
		<swiper-tab-head :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap"></swiper-tab-head>
		<view class="uni-tab-bar">
			<swiper class="swiper-box" :style="{'height': swiperHeight + 'px'}" :current="tabIndex" @change="tabChange">
				<swiper-item v-for="(items,index) in newsList" :key="index">
					<scroll-view scroll-y class="list" @scrolltolower="loadmore(index)">
						<template v-if="items.list.length > 0">
							<!-- 话题列表 -->
							<view class="px-2">
								<block v-for="(item,indey) in items.list" :key="indey">
									<news-topic-list :item="item" :index="indey"></news-topic-list>
								</block>
							</view>

							<!-- 上拉加载 -->
							<load-more :loadtext="items.loadtext"></load-more>
						</template>
						<template v-else>
							<!-- 无内容默认 -->
							<no-thing></no-thing>
						</template>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import swiperTabHead from "../../components/index/swiper-tab-head.vue"
	import loadMore from "../../components/common/load-more.vue"
	import noThing from "../../components/common/no-thing.vue"
	import newsTopicList from "../../components/news/news-topic-list.vue"
	export default {
		data() {
			return {
				swiperHeight: 500,
				tabIndex: 0,
				tabBars: [{
						name: "关注",
						id: "guanzhu"
					},
					{
						name: "推荐",
						id: "tuijian"
					},
					{
						name: "体育",
						id: "tiyu"
					},
					{
						name: "热点",
						id: "redian"
					},
					{
						name: "财经",
						id: "caijing"
					}
				],
				newsList: [{
						loadtext: "上拉加载更多",
						list: [{
								titlepic: "../../static/image/topicpic/13.jpeg",
								title: "话题名称话题名称",
								desc: "我是话题描述",
								totalnum: 50,
								todaynum: 30
							},
							{
								titlepic: "../../static/image/topicpic/13.jpeg",
								title: "话题名称话题名称2",
								desc: "我是话题描述2",
								totalnum: 40,
								todaynum: 30
							},
							{
								titlepic: "../../static/image/topicpic/13.jpeg",
								title: "话题名称话题名称3",
								desc: "我是话题描述我是话题描述我是话题描述我是话题描述我是话题描述我是话题描述我是话题描述我是话题描述我是话题描述我是话题描述我是话题描述我是话题描述3",
								totalnum: 60,
								todaynum: 30
							},
							{
								titlepic: "../../static/image/topicpic/13.jpeg",
								title: "话题名称话题名称3",
								desc: "我是话题描述3",
								totalnum: 60,
								todaynum: 30
							},
							{
								titlepic: "../../static/image/topicpic/13.jpeg",
								title: "话题名称话题名称3",
								desc: "我是话题描述3",
								totalnum: 60,
								todaynum: 30
							},
							{
								titlepic: "../../static/image/topicpic/13.jpeg",
								title: "话题名称话题名称3",
								desc: "我是话题描述3",
								totalnum: 60,
								todaynum: 30
							}
						]
					},
					{
						loadtext: "上拉加载更多",
						list: []
					},
					{
						loadtext: "上拉加载更多",
						list: []
					},
					{
						loadtext: "上拉加载更多",
						list: []
					},
					{
						loadtext: "上拉加载更多",
						list: []
					}
				]
			};
		},
		methods: {
			// 点击
			tabtap(index) {
				this.tabIndex = index
			},
			// 滑动
			tabChange(e) {
				this.tabIndex = e.detail.current;
			},
			// 上拉加载
			loadmore(index) {
				if (this.newsList[index].loadtext !== "上拉加载更多") {
					return
				}
				// 修改状态
				this.newsList[index].loadtext = "拼命加载中. . ."
				setTimeout(() => {
					this.newsList[index].loadtext = "人家是有底线的 Ծ ‸ Ծ"
				}, 1000)
			}
		},
		components: {
			swiperTabHead,
			loadMore,
			noThing,
			newsTopicList
		},
		onLoad() {
			// 解决滚动高度问题
			uni.getSystemInfo({
				success: (res) => {
					let height = res.windowHeight - uni.upx2px(100);
					this.swiperHeight = height
				}
			})
		}
	}
</script>

<style lang="scss">
</style>
